import React from 'react';
import { withRouter } from 'react-router-dom';
import './Topbar.css'
class Navbar extends React.Component {

	constructor(props) {
	  super(props);
	  this.state = {
		pathname:this.props.location,
        barname:"",
        selectval:'none',
        name:this.props.name,
        color:props.color,
        mylink:''
	  };
	}

    showMenu(){
        if(this.state.selectval==='none'){
            this.setState({
                selectval:'block'
            })
        }else if(this.state.selectval==='block'){
            this.setState({
                selectval:'none'
            })
        }
    }

    goBack(){
        window.history.back(-1);
    }

    ifLogin(){//判断是否登录
        
        
        

    }

	render() {
		const {pathname} =this.props.location;
        return (
            <nav>
                <div className="navbar-div">
                    <i className="iconfont icon-fanhui" 
                        style={{
                            color:this.state.color,
                            width: '10%',
                            height: 30,
                            marginTop: 20,
                            float: 'left'
                        }} 
                        onClick={this.goBack.bind(this)}
                    ></i>
                    <div className="barname">{this.state.name}</div>
                    <button className="abutton" style={{marginTop: 20}}onClick={this.showMenu.bind(this)}>
                        <span className="pan" style={{backgroundColor: this.state.color}}></span>
                        <span className="pan" style={{backgroundColor: this.state.color}}></span>
                        <span className="pan" style={{backgroundColor: this.state.color}}></span>
                    </button>
                </div>

                <div className="menu" style={{display: this.state.selectval,position: 'absolute',zIndex: 999999,backgroundColor: this.state.color}}>
                    <ul>
                        
                        <li><a href="/">首页</a></li>
                        {
                            localStorage.getItem("token")
                            ?
                            <li><a href='/My'>个人中心</a></li>
                            :
                            <li><a href="/Login">登录</a></li>
                        }
                        <li><a href="/Activity">活动广场</a></li>
                        <li><a href="/Share">交流圈</a></li>
                        <li><a href="/Exchange">闲置阁</a></li>
                        <li><a href="/Confession">遇见桃花</a></li>
                        
                    </ul>
                </div>
            </nav>
        );
	}
}

export default withRouter(Navbar);